package com.example.prototypedemo.entityu;

import java.io.*;

/**
 * @author godShan
 * @Description:
 * @date 2019/5/6 14:08
 */
public class Man extends Person implements Cloneable, Serializable {

    public GirlFriend girl;

    public Man() {
        this.girl = new GirlFriend();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return this.deepClone();
    }

    private Object deepClone() {

        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);
            oos.flush();
            oos.close();

            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            return ois.readObject();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    public Object shallowClone(Man man) {
        Man m = new Man();
        m.girl = man.girl;
        m.height = man.height;
        m.weight = man.weight;
        m.birthday = man.birthday;
        return m;
    }

}
